package configuration;

import java.io.*;
import java.util.*;

/**
 * The configuration file is maintains the parameters used to fine-tune the
 * performances of the algorithms
 * 
 * @author Nodirjon Siddikov
 */
public class Configuration {
	// memory measurements are in bytes
	public static int localCacheSize, tagSize, localCacheBlockLifeTime,
			localCacheBlockSize, globalCacheBlockSize, noOfBlocks, blockSize,
			bloomFilterConstructor, bloomFilterLoadFactor, noOfHashFunctions,
			broadcastInterval, noOfClients, recirculationCount, algorithm,
			noOfReadRequests, hintSize, hintCount, detailedStats, trace;
	public static double cacheAccessTime, storageAccessTime,
			bloomFilterFalseProbability, warmup, messageLatency;

	// parse the config file
	public static void parse(String configFile) throws FileNotFoundException {
		Scanner scanner = new Scanner(new File(configFile));
		int count = 0;
		while (scanner.hasNextLine()) {
			try {
				// read the line
				String line = scanner.nextLine();
				// extract parameter from a line
				String parameter = line.split(":")[1].trim();
				switch (count) {
				case 0:
					algorithm = Integer.parseInt(parameter);
					break;
				case 1:
					noOfClients = Integer.parseInt(parameter);
					break;
				case 2:
					noOfReadRequests = Integer.parseInt(parameter);
					break;
				case 3:
					trace = Integer.parseInt(parameter);
					break;
				case 4:
					warmup = Double.parseDouble(parameter);
					break;
				case 5:
					detailedStats = Integer.parseInt(parameter);
					break;
				case 6:
					localCacheSize = Integer.parseInt(parameter);
					break;
				case 7:
					globalCacheBlockSize = Integer.parseInt(parameter);
					break;
				case 8:
					tagSize = Integer.parseInt(parameter);
					break;
				case 9:
					cacheAccessTime = Double.parseDouble(parameter);
					break;
				case 10:
					messageLatency = Double.parseDouble(parameter);
					break;
				case 11:
					storageAccessTime = Double.parseDouble(parameter);
					break;
				case 12:
					noOfBlocks = Integer.parseInt(parameter);
					break;
				case 13:
					blockSize = Integer.parseInt(parameter);
					break;
				case 14:
					recirculationCount = Integer.parseInt(parameter);
					break;
				case 15:
					hintSize = Integer.parseInt(parameter);
					break;
				case 16:
					hintCount = Integer.parseInt(parameter);
					break;
				case 17:
					bloomFilterConstructor = Integer.parseInt(parameter);
					break;
				case 18:
					bloomFilterLoadFactor = Integer.parseInt(parameter);
					break;
				case 19:
					bloomFilterFalseProbability = Double.parseDouble(parameter);
					break;
				case 20:
					noOfHashFunctions = Integer.parseInt(parameter);
					break;
				case 21:
					broadcastInterval = Integer.parseInt(parameter);
					break;
				case 22:
					localCacheBlockLifeTime = Integer.parseInt(parameter);
					break;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			// increment counter
			count++;
		}
		localCacheBlockSize = tagSize + blockSize;
	}
}